/**
 * 20080124 1157: Eric Kao was created.
 */

package pre;

import java.sql.Connection;

/**
 * 針業 table(TEST_TABLE), 來建立相關的基本 method<br>
 * <br>
 * Copyright: Copyright (c) 2001-2008<br>
 * Company: E885 Group
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 */
public class PreTestTable extends AbstractPreTable
{
	/**
	 * Column:ID
	 */
	public static String ID_CONSTANT = "ID";

	/**
	 * Column:NAME
	 */
	public static String NAME_CONSTANT = "NAME";

	/**
	 * Column:ADDRESS
	 */
	public static String ADDRESS_CONSTANT = "ADDRESS";

	private String ID = "id"; // insert data for id

	private String NAME = "姓名"; // insert data for name

	private String ADDRESS = "地址"; // insert data for address

	public PreTestTable( Connection connection )
	{
		super( connection );
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jdbc.pre.AbstractPreTable#generateCreatingTableSQL()
	 */
	@Override
	protected String generateCreatingTableSQL()
	{
		String tempString = "";

		tempString = tempString.concat( "create table TEST_TABLE" );
		tempString = tempString.concat( "(" );
		tempString = tempString.concat( " ID varchar(20) not null," );
		tempString = tempString.concat( " NAME varchar(50) not null," );
		tempString = tempString.concat( " ADDRESS varchar(100)," );
		tempString = tempString.concat( " constraint TEST_TABLE_PK primary key (ID)" );
		tempString = tempString.concat( " )" );

		return tempString;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jdbc.pre.AbstractPreTable#generateDropingTableSQL()
	 */
	@Override
	protected String generateDroppingTableSQL()
	{
		String tempString = "";

		tempString = tempString.concat( "drop table TEST_TABLE" );

		return tempString;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jdbc.pre.AbstractPreTable#generateSelectingDataSQL()
	 */
	@Override
	protected String generateSelectingDataSQL()
	{
		String tempString = "";

		tempString = tempString.concat( "select * from TEST_TABLE" );

		return tempString;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jdbc.pre.AbstractPreTable#generateInsertingDataSQL()
	 */
	@Override
	protected String[] generateInsertingDataSQLs( int size )
	{
		String tempString = "";

		String[] sqls = new String[ size ];

		for( int i = 0; i < size; i++ )
		{
			tempString = tempString.concat( "insert into TEST_TABLE( ID, NAME, ADDRESS ) values" );
			tempString = tempString.concat( "(" );
			tempString = tempString.concat( " '" + ID + "_" + ( i + 1 ) + "'" );
			tempString = tempString.concat( ", '" + NAME + "_" + ( i + 1 ) + "'" );
			tempString = tempString.concat( ", '" + ADDRESS + "_" + ( i + 1 ) + "'" );
			tempString = tempString.concat( ")" );

			sqls[ i ] = tempString;

			tempString = "";
		}

		return sqls;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jdbc.pre.AbstractPreTable#generateUpdatingDataSQL()
	 */
	@Override
	protected String generateUpdatingDataSQL( String id )
	{
		String tempString = "";

		tempString = tempString.concat( "update TEST_TABLE set" );
		tempString = tempString.concat( " NAME='" + NAME + "_Modify" + "'" );
		tempString = tempString.concat( " where" );
		tempString = tempString.concat( " ID='" + id + "'" );

		return tempString;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jdbc.pre.AbstractPreTable#generateDeletingDataSQL()
	 */
	@Override
	protected String generateDeletingDataSQL( String id )
	{
		String tempString = "";

		tempString = tempString.concat( "delete from TEST_TABLE" );
		tempString = tempString.concat( " where" );
		tempString = tempString.concat( " ID='" + id + "'" );

		return tempString;
	}
}
